package com.eamois.dao.manual.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.eamois.dao.impl.BaseDaoImpl;
import com.eamois.dao.manual.GengralRulesDao;
import com.eamois.domain.manual.Catalog;
import com.eamois.domain.manual.GengralRules;
import com.eamois.domain.manual.Technology;
import com.incors.plaf.alloy.cr;

public class GengralRulesDaoImpl extends BaseDaoImpl<GengralRules> implements GengralRulesDao{

	@Override
	public GengralRules findGengralRulesByTechnology(final Technology technology) {
		// TODO Auto-generated method stub
		return (GengralRules)this.getHibernateTemplate().execute(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = session.createCriteria(GengralRules.class);
				criteria.add(Restrictions.eq("technology", technology));
				ArrayList<GengralRules> list = (ArrayList<GengralRules>)criteria.list();
				if (list.size() == 0) {
					return null;
				}else{
					return list.get(0);
				}
			}
		});
	}

	@Override
	public GengralRules findGengralRulesByCatalogAndTechnology(final Catalog catalog,
			final Technology technology) {
		// TODO Auto-generated method stub
		return (GengralRules)this.getHibernateTemplate().execute(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = session.createCriteria(GengralRules.class);
				criteria.add(Restrictions.eq("technology", technology));
				criteria.add(Restrictions.eq("catalog", catalog));
				ArrayList<GengralRules> list = (ArrayList<GengralRules>)criteria.list();
				if (list.size() == 0) {
					return null;
				}else{
					return list.get(0);
				}
			}
		});
	}

}
